/*
 * File:   main.cpp
 * Author: Morpheus
 *
 * Created on 19 juin 2013, 22:59
 */

#include <QtWidgets/qapplication.h>
#include <QtWidgets/qsplashscreen.h>

#include "MainWindow.h"

void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg){

    QByteArray localMsg = msg.toLocal8Bit();
    switch (type) {
    case QtDebugMsg:
        fprintf(stdout, "Debug : %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        fflush(stdout);
        break;
    case QtWarningMsg:
        fprintf(stdout, "Warning : %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        fflush(stdout);
        break;
    case QtCriticalMsg:
        fprintf(stdout, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        fflush(stdout);
        break;
    case QtFatalMsg:
        fprintf(stdout, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
        fflush(stdout);
        abort();
    }
}


int main(int argc, char *argv[]) {
    // initialize resources, if needed
    // Q_INIT_RESOURCE(resfile);

    QApplication app(argc, argv);
    
    QPixmap pixmap(":/res/nice_try.png");
    QSplashScreen splash(pixmap);
    splash.showMessage(QObject::tr("Chargement..."), Qt::AlignLeft | Qt::AlignBottom, Qt::black);
    splash.show();
    app.processEvents();

    qInstallMessageHandler(myMessageOutput);

    app.setApplicationName("FileMerger");
    app.setApplicationVersion("1.0.0.5");
    app.setOrganizationName("Morpheus Corporate");
    app.setOrganizationDomain("cgmorpheus.myftp.biz");

    // create and show your widgets here
    MainWindow w;
    QObject::connect(&w, SIGNAL(showMessage(QString, int, QColor)), &splash, SLOT(showMessage(QString, int, QColor)));
    w.initialed();
    splash.finish(&w);
    w.show();
    
    return app.exec();
}
